package org.destiny.swing.mapping.base;

import java.awt.Dimension;
import java.lang.reflect.Field;

import javax.swing.JComponent;
import javax.swing.JTextField;

public class TextComponentMapper extends AbstractFormItemMapper<String> {

	private JTextField textField;
	private String fieldValue;

	public TextComponentMapper(Field field) {
		super(field);
		textField = new JTextField();
		Dimension prefSize = textField.getPreferredSize();
		int prefWidth = formItem.prefWidth();
		int prefHeight = formItem.prefHeight();
		if (prefWidth != -1) {
			prefSize.width = prefWidth;
		}
		if (prefHeight != -1) {
			prefSize.height = prefHeight;
		}
		textField.setPreferredSize(prefSize);
	}

	@Override
	public JComponent getInputComponent() {
		return textField;
	}

	@Override
	public String getFieldValue() {
		return fieldValue;
	}
	
	@Override
	public void setFieldValue(String fieldValue) {
		this.fieldValue = fieldValue;
	}

}
